from django.contrib import admin
from .models import HrChatSession, HrChatMessage


@admin.register(HrChatSession)
class HrChatSessionAdmin(admin.ModelAdmin):
    list_display = ['id', 'user', 'title', 'created_at', 'updated_at', 'is_archived']
    list_filter = ['created_at', 'is_archived']
    search_fields = ['title', 'user__username']
    readonly_fields = ['created_at', 'updated_at']


@admin.register(HrChatMessage)
class HrChatMessageAdmin(admin.ModelAdmin):
    list_display = ['id', 'session', 'sender', 'content_preview', 'created_at', 'tokens_used']
    list_filter = ['sender', 'created_at']
    search_fields = ['content', 'session__title']
    readonly_fields = ['created_at']

    def content_preview(self, obj):
        return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
    content_preview.short_description = '消息预览'